package com.banmao.CarlCamp.Day05;

import java.util.HashMap;

/**
 * https://leetcode.cn/problems/valid-anagram/
 */
public class LC242_2 {

    public boolean isAnagram(String s, String t) {
        if (s.length() != t.length()) {
            return false;
        }

        // 如果不考虑其他中文字符，那当然是用数组做更快
        int[] arr = new int[1024];
        byte[] sBytes = s.getBytes();
        byte[] tBytes = t.getBytes();
        for (byte sByte : sBytes) {
            arr[sByte]++;
        }
        for (byte tByte : tBytes) {
            arr[tByte]--;
        }
        for (int j : arr) {
            if (j != 0) {
                return false;
            }
        }

        return true;
    }

    public static void main(String[] args) {
        LC242_2 lc242 = new LC242_2();
        lc242.isAnagram("你好", "你好");

    }

}
